<template>
	<view>
		<view class=detail>
			<view class="title">{{detail.title}}</view>
			<view class="info">
				<view class="author">
					编辑：{{detail.author}}
				</view>
				<view class="time">
					发布时间：{{detail.posttime}}
				</view>

		</view>
		<view class="content">
				<rich-text :nodes="detail.content"></rich-text>
			</view>
			<view class="des">
				版权声明
			</view>
		</view>
		
	</view>
</template>

<script>
	import {parseTime} from "@/utils/tool.js"
	export default {
		data() {
			return {
				options:null,
				detail:{}
			};
		},
		onLoad(event) {
			this.options = event
			this.getDetail()
		},
		methods:{
			getDetail(){
				uni.request({
					url:"https://ku.qingnian8.com/dataApi/news/detail.php",
					data:this.options,
					success:res=>{
						res.data.posttime = parseTime(res.data.posttime)
						res.data.content = res.data.content.replace(/<img/gi,'<img style="max-width:100%"')
						this.detail = res.data
						
						this.saveHistory()
						
						uni.setNavigationBarTitle({
							title:this.detail.title
						})
					}
				})
			},
			saveHistory(){
				let historyList = uni.getStorageSync("historyList") || []
				let item = {
					id:this.detail.id,
					classid:this.detail.classid,
					picurl:this.detail.picurl,
					looktime:parseTime(Date.now()),
					title:this.detail.title
				}
				
				let index = historyList.findIndex(i=>{
					return i.id==this.detail.id
				})
				//已有删除
				if(index >= 0){
					historyList.splice(index,1)
				}
				
				historyList.unshift(item)
				uni.setStorageSync("historyList",historyList)
			}
		},
	}
</script>

<style lang="scss">
.detail{
	padding: 30rpx;
	.title{
		font-size: 46rpx;
		color: #333;
		
	}
	.info{
		background-color: #f6f6f6;
		padding: 10rpx;
		font-size: 20rpx;
		color: #666;
		display: flex;
		justify-content: space-between;
		margin: 40rpx 0;
	}
	.content{
		padding-bottom: 50rpx;
		/deep/ img{
			max-width: 100%;
		}
	}
	.des{
		background-color: #fef0f0;
		font-size: 26rpx;
		padding: 20rpx;
		color: #f89898;
		line-height: 1.8em;
	}
}
</style>
